// Package datasource @author dingrui @since 2021/11/26
package datasource

import (
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
)

var (
	// 单例
	G_ormEngine *xorm.Engine
)

func init() {
	G_ormEngine = newDBConnection()
}

//
//  newDBConnection
//  @Description: 创建数据库连接
//  @return *xorm.Engine
//
func newDBConnection() (instance *xorm.Engine) {
	var (
		source string
		err    error
	)
	source = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8",
		"root",
		"19920308",
		"localhost",
		3306,
		"prize")

	if instance, err = xorm.NewEngine("mysql", source); err != nil {
		log.Fatal("dbhelper.InstanceDbMaster NewEngine error ", err)
		return nil
	}
	instance.ShowSQL(true)
	return
}
